package cn.minimelon.api.controller.data;

import cn.hutool.core.util.StrUtil;
import cn.minimelon.api.controller.common.BaseController;
import cn.minimelon.api.domain.common.AjaxResult;
import cn.minimelon.api.domain.common.LoginUser;
import cn.minimelon.api.domain.common.PageQuery;
import cn.minimelon.api.domain.common.TableDataInfo;
import cn.minimelon.api.domain.data.ApplySaveVO;
import cn.minimelon.api.domain.data.CodeBaseVO;
import cn.minimelon.api.domain.data.CodeIndexVO;
import cn.minimelon.api.exception.BaseException;
import cn.minimelon.api.service.data.CodeApplyService;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.core.handle.MethodType;

/**
 * 申请页面相关接口
 */
@Controller
@Mapping("/data")
public class CodeApplyController extends BaseController {

    @Inject
    private CodeApplyService codeApplyService;

    /**
     * 申请分页查询接口
     */
    @Mapping(value = "/{area}/apply/page", method = MethodType.POST)
    public TableDataInfo selectApplyPage(PageQuery<CodeIndexVO> pageQuery) {
        LoginUser user = getLoginUser();
        return codeApplyService.selectApplyPage(pageQuery, user);
    }

    @Mapping(value = "/{area}/apply/save", method = MethodType.POST)
    public AjaxResult saveData(ApplySaveVO applySave) {
        if (StrUtil.isEmpty(applySave.getModelCode())) {
            throw new BaseException("data", "param.not.null", "模型编码");
        }
        LoginUser user = getLoginUser();
        CodeBaseVO data = codeApplyService.saveUIListData(applySave, user);
        return AjaxResult.success(data);
    }
}
